#include <iostream>
#include "CommandLineParser.h"

using namespace std;
using namespace tsc::common;

//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
void parseCase1()
{
  CommandLineParser* parser = 0;

  int argc = 1;
  const char* argv[] =
  {
    "parseCase1"
  };

  try
  {
    parser = new CommandLineParser(argc, argv);

    cout << argv[0] << ": Is option switch '-n' present?" << endl;
    cout << argv[0] << ": " << (parser->isKeyPresent("n") ? "Yes" : "No") << endl;

    cout << argv[0] << ": Is option switch '--non-existing-option' present?" << endl;
    cout << argv[0] << ": " << (parser->isKeyPresent("non-existing-option") ? "Yes" : "No") << endl;
    cout << argv[0] << ": Value of '--non-existing-option' is:" << endl;
    cout << argv[0] << ": " << parser->getValue<string>("non-existing-option") << endl;
  }
  catch(std::ios_base::failure& e)
  {
    cout << argv[0] << ": Caught exception:\n" << e.what() << endl;
  }

  delete parser;
}

//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
void parseCase2()
{
  CommandLineParser* parser = 0;

  int argc = 3;
  const char* argv[] =
  {
    "parseCase2",
    "-h",
    "--help"
  };

  try
  {
    parser = new CommandLineParser(argc, argv);

    cout << argv[0] << ": Is option switch '"<<argv[1]<<"' present?" << endl;
    cout << argv[0] << ": " << (parser->isKeyPresent(argv[1]+1) ? "Yes" : "No") << endl;
    cout << argv[0] << ": Value of '"<<argv[1]<<"' is:" << endl;
    cout << argv[0] << ": " << parser->getValue<string>(argv[1]+1) << endl;

    cout << argv[0] << ": Is option switch '"<<argv[2]<<"' present?" << endl;
    cout << argv[0] << ": " << (parser->isKeyPresent(argv[2]+2) ? "Yes" : "No") << endl;
    cout << argv[0] << ": Value of '"<<argv[2]<<"' is:" << endl;
    cout << argv[0] << ": " << parser->getValue<string>(argv[2]+2) << endl;
  }
  catch(std::ios_base::failure& e)
  {
    cout << argv[0] << ": Caught exception:\n" << e.what() << endl;
  }

  delete parser;
}

//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
void parseCase3()
{
  CommandLineParser* parser = 0;

  int argc = 5;
  const char* argv[] =
  {
    "parseCase3",
    "-s",
    "value_for_switch_s",
    "--status",
    "value_for_switch_status"
  };

  try
  {
    parser = new CommandLineParser(argc, argv);

    cout << argv[0] << ": Is option switch '"<<argv[1]<<"' present?" << endl;
    cout << argv[0] << ": " << (parser->isKeyPresent(argv[1]+1) ? "Yes" : "No") << endl;
    cout << argv[0] << ": Value of '"<<argv[1]<<"' is:" << endl;
    cout << argv[0] << ": " << parser->getValue<string>(argv[1]+1) << endl;

    cout << argv[0] << ": Is option switch '"<<argv[3]<<"' present?" << endl;
    cout << argv[0] << ": " << (parser->isKeyPresent(argv[3]+2) ? "Yes" : "No") << endl;
    cout << argv[0] << ": Value of '"<<argv[3]<<"' is:" << endl;
    cout << argv[0] << ": " << parser->getValue<string>(argv[3]+2) << endl;
  }
  catch(std::ios_base::failure& e)
  {
    cout << argv[0] << ": Caught exception:\n" << e.what() << endl;
  }

  delete parser;
}

//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
void parseCase4()
{
  CommandLineParser* parser = 0;

  int argc = 2;
  const char* argv[] =
  {
    "parseCase4",
    "-long_name",
  };

  try
  {
    parser = new CommandLineParser(argc, argv);
  }
  catch(std::ios_base::failure& e)
  {
    cout << argv[0] << ": Caught exception:\n" << e.what() << endl;
  }

  delete parser;
}

//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
void parseCase5()
{
  CommandLineParser* parser = 0;

  int argc = 5;
  const char* argv[] =
  {
    "parseCase5",
    "-d",
    "some_value",
    "--duplicate",
    "-d",
  };

  try
  {
    parser = new CommandLineParser(argc, argv);
  }
  catch(std::ios_base::failure& e)
  {
    cout << argv[0] << ": Caught exception:\n" << e.what() << endl;
  }

  delete parser;
}

//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
void parseCase6()
{
  CommandLineParser* parser = 0;

  int argc = 5;
  const char* argv[] =
  {
    "parseCase6",
    "--duplicate",
    "some_value",
    "-d",
    "--duplicate",
  };

  try
  {
    parser = new CommandLineParser(argc, argv);
  }
  catch(std::ios_base::failure& e)
  {
    cout << argv[0] << ": Caught exception:\n" << e.what() << endl;
  }

  delete parser;
}


int main(int argc, char* argv[])
{
  parseCase1();
  parseCase2();
  parseCase3();
  parseCase4();
  parseCase5();
  parseCase6();

  return 0;
}

